package com.score.controller;

import com.score.pojo.ReturnEntry;
import com.score.pojo.TLeaveRequest;
import com.score.service.impl.LeaveRequestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/leave")
public class LeaveRequestController {
    @Autowired
    private LeaveRequestServiceImpl leaveRequestService;

    /**
     * 学生申请请假
     * @param leaveRequest
     * @return
     */
    @Secured("ROLE_student")
    @PostMapping("/stuapply")
    public ReturnEntry stuApplyLeave(TLeaveRequest leaveRequest){
        return leaveRequestService.stuApplyLeave(leaveRequest);
    }

    /**
     * 学生获取正在请假的信息
     * @param stuNum
     * @param username
     * @return
     */
    @Secured("ROLE_student")
    @PostMapping("/stugetapply")
    public ReturnEntry stuGetLeave(String stuNum,String username){
        return leaveRequestService.stuGetLeave(stuNum,username);
    }

    /**
     * 学生获取未通过请假信息
     * @param stuNum
     * @param username
     * @return
     */
    @Secured("ROLE_student")
    @PostMapping("/stugetunpass")
    public ReturnEntry stuGetUnpass(String stuNum,String username){
        return leaveRequestService.stuGetUnpass(stuNum,username);
    }

    /**
     * 学生获取未销假和正在销假信息
     * @param stuNum
     * @param username
     * @return
     */
    @Secured("ROLE_student")
    @PostMapping("/stugetuncancel")
    public ReturnEntry stuGetUncancel(String stuNum,String username){
        return leaveRequestService.stuGetUncancel(stuNum,username);
    }

    /**
     * 学生获取已销假信息
     * @param stuNum
     * @param username
     * @return
     */
    @Secured("ROLE_student")
    @PostMapping("/stugetcancel")
    public ReturnEntry stuGetCancel(String stuNum,String username){
        return leaveRequestService.stuGetCancel(stuNum,username);
    }

    /**
     * 学生销假
     * @param leaveRequest
     * @return
     */
    @Secured("ROLE_student")
    @PostMapping("/stutocancel")
    public ReturnEntry stuToCancel(TLeaveRequest leaveRequest){
        return leaveRequestService.stuToCancel(leaveRequest);
    }

    /**
     * 根据老师的不同身份获取不同的假条未读信息并分页
     * @param position
     * @param college
     * @param className
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/teagetapplytopage")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaGetLeaveApplyToPage(String position,String college,String className, Integer currentPage, Integer pageSize){
        return leaveRequestService.teaGetLeaveApplyToPage(position,college,className,currentPage,pageSize);
    }

    /**
     * 根据老师的不同身份获取不同的假条未通过信息并分页
     * @param position
     * @param college
     * @param className
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/teagetunpass")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaGetUnpassToPage(String position,String college,String className, Integer currentPage, Integer pageSize){
        return leaveRequestService.teaGetUnpassToPage(position,college,className,currentPage,pageSize);
    }

    /**
     * 根据老师的不同身份获取不同的假条未销假信息并分页
     * @param position
     * @param college
     * @param className
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/teagetuncancel")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaGetUncancel(String position,String college,String className, Integer currentPage, Integer pageSize){
        return leaveRequestService.teaGetUncancel(position,college,className,currentPage,pageSize);
    }

    /**
     * 根据老师的不同身份获取不同的假条已销假信息并分页
     * @param position
     * @param college
     * @param className
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/teagetcancel")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaGetCancel(String position,String college,String className, Integer currentPage, Integer pageSize){
        return leaveRequestService.teaGetCancel(position,college,className,currentPage,pageSize);
    }

    /**
     * 老师同意请假
     * @param position
     * @param leaveRequest
     * @return
     */
    @PostMapping("/teaagreeapply")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaAgreeApply(String position,TLeaveRequest leaveRequest){
        return leaveRequestService.teaAgreeApply(position,leaveRequest);
    }

    /**
     * 老师不同意请假
     * @param position
     * @param leaveRequest
     * @return
     */
    @PostMapping("/teaunagreeapply")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaUnagreeApply(String position,TLeaveRequest leaveRequest){
        return leaveRequestService.teaUnagreeApply(position,leaveRequest);
    }

    /**
     * 老师不同意销假
     * @param leaveRequest
     * @return
     */
    @PostMapping("/teaagreeuncancel")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaAgreeUncancel(TLeaveRequest leaveRequest){
        return leaveRequestService.teaAgreeUncancel(leaveRequest);
    }

    /**
     * 老师同意销假
     * @param leaveRequest
     * @return
     */
    @PostMapping("/teaagreecancel")
    @Secured({"ROLE_headmaster","ROLE_instructor","ROLE_deputySecretary","ROLE_dean"})
    public ReturnEntry teaAgreeCancel(TLeaveRequest leaveRequest){
        return leaveRequestService.teaAgreeCancel(leaveRequest);
    }
}
